'use strict' import hostingService from '../../../src/data/bots/{id}/hosting' import { authenticate, checkRole } from '../../../auth' import { Operation } from 'express-openapi' /** * Operations on /bots/{id}/hosting */ export default function() { /**Creates new hosting for bot */ const POST: Operation = async (req, res, next) => { const { isAllowedUser, role } = req.user if (!isAllowedUser && !checkRole(role, 'view')) { console.error('No permission to post hosting') res.status(401).send() } else { try { res.status(200).json(await hostingService.postHosting(req)) } catch (error) { res.status(error.code || 500).send(error.message) } } } const PATCH: Operation = async (req, res, next) => { try { res.status(200).json(await hostingService.patchHosting(req)) } catch (error) { console.error(error) res.status(error.code || 500).send(error.message) } } return { POST: [authenticate(['allowed-users', 'bot-token']), POST], PATCH } }